package cn.itcast.nems.journal.service.impl;

import cn.itcast.nems.journal.api.JournalTransferLineDiscountApi;
import cn.itcast.nems.journal.dto.JournalTransferLineDiscountDTO;
import cn.itcast.nems.journal.service.JournalTransferLineDiscountService;
import cn.itcast.nems.manager.util.CustomBeanUtil;
import cn.itcast.nems.studentrecord.dao.entity.JournalTransferLineDiscount;
import cn.itcast.nems.studentrecord.dao.mapper.JournalTransferLineDiscountMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 * 转班凭单-优惠明细;包括针对转班凭单的优惠和针对学生的优惠。 服务实现类
 * </p>
 *
 * @author liyong
 * @since 2023-11-14
 */
@Service
@RequiredArgsConstructor
public class JournalTransferLineDiscountServiceImpl implements JournalTransferLineDiscountService, JournalTransferLineDiscountApi {
    private final JournalTransferLineDiscountMapper journalTransferLineDiscountMapper ;

    @Override
    public List<JournalTransferLineDiscountDTO> findListByTransferIdAndLineId(String transferId, String lineId) {
        List<JournalTransferLineDiscount> list = journalTransferLineDiscountMapper.selectList(
                new LambdaQueryWrapper<JournalTransferLineDiscount>()
                        .eq(JournalTransferLineDiscount::getJournalTransferId, transferId)
                        .eq(JournalTransferLineDiscount::getDeletedFlag, false)
                        .eq(JournalTransferLineDiscount::getJournalTransferLineId, lineId));
        return Objects.requireNonNullElse(list, new ArrayList<JournalTransferLineDiscount>()).stream()
                .map(v -> CustomBeanUtil.copyProperties(v, new JournalTransferLineDiscountDTO())).collect(Collectors.toList());
    }
}
